package com.hongye.broker.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hongye.broker.mapper.HouseMapper;
import com.hongye.broker.service.HouseService;
import com.hongye.common.entity.HouseEntity;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.ObjectUtil;
import com.hongye.broker.vo.HouseSelectVo;
import com.hongye.common.response.ResponseResult;
import java.util.HashMap;
import java.util.List;

@Service
public class HouseServiceImpl extends ServiceImpl<HouseMapper,HouseEntity> implements HouseService {



    @Override
    public List<HouseEntity> maifang() {
        QueryWrapper<HouseEntity> queryWrapper = Wrappers.query();
        queryWrapper.eq("status", 0);
        queryWrapper.orderByDesc("update_time");
        List<HouseEntity> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public ResponseResult list(HouseSelectVo houseSelectVo) {
        if (ObjectUtil.isNull(houseSelectVo)){
            QueryWrapper<HouseEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("is_new_house",1);
            queryWrapper.orderByDesc("create_time");
            List<HouseEntity> houseEntities = baseMapper.selectList(queryWrapper);
            HashMap<String, Object> map = new HashMap<>();
            map.put("list",houseEntities);
            return ResponseResult.ok(1,"ok",map);
        }


        QueryWrapper<HouseEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("country_id",houseSelectVo.getCountry());
        queryWrapper.between("total_price",houseSelectVo.getMinPrice(),houseSelectVo.getMaxPrice());
        queryWrapper.eq("room_type",houseSelectVo.getRoomType());
        queryWrapper.eq("orientation",houseSelectVo.getOrientation());
        queryWrapper.eq("house_type_id",houseSelectVo.getHouseTypeId());
        queryWrapper.orderByDesc("create_time");
        queryWrapper.eq("is_new_house",1);

        List<HouseEntity> houseEntities = baseMapper.selectList(queryWrapper);
        HashMap<String, Object> map = new HashMap<>();
        map.put("list",houseEntities);
        return ResponseResult.ok(1,"ok",map);
    }

    @Override
    public ResponseResult twoList(HouseSelectVo houseSelectVo) {
        if (ObjectUtil.isNull(houseSelectVo)){
            QueryWrapper<HouseEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("is_new_house",1);
            queryWrapper.orderByDesc("create_time");
            List<HouseEntity> houseEntities = baseMapper.selectList(queryWrapper);
            HashMap<String, Object> map = new HashMap<>();
            map.put("list",houseEntities);
            return ResponseResult.ok(1,"ok",map);
        }


        QueryWrapper<HouseEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("country_id",houseSelectVo.getCountry());
        queryWrapper.between("total_price",houseSelectVo.getMinPrice(),houseSelectVo.getMaxPrice());
        queryWrapper.eq("room_type",houseSelectVo.getRoomType());
        queryWrapper.eq("orientation",houseSelectVo.getOrientation());
        queryWrapper.eq("house_type_id",houseSelectVo.getHouseTypeId());
        queryWrapper.orderByDesc("create_time");
        queryWrapper.eq("is_new_house",2);

        List<HouseEntity> houseEntities = baseMapper.selectList(queryWrapper);
        HashMap<String, Object> map = new HashMap<>();
        map.put("list",houseEntities);
        return ResponseResult.ok(1,"ok",map);
    }
}
